package ar.Location.Api.Eventful;

import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.SAXParserFactory;

import android.util.Log;
import android.util.Xml;
import ar.Location.Constant.Define;
import ar.Location.Helper.HttpProvider;
import ar.Location.PlaceApi.AbsAPI;
import ar.Location.PlaceObject.Place;
import ar.globals.Globals;

public class EventfulAPI extends AbsAPI {

	private static final String TAG = "EventfulAPI";

	@Override
	public ArrayList<Place> getListPlacesByGeoPoint(String latitude,
			String longitude, int radiusMetters) {
		// TODO Auto-generated method stub
		try {
			String url = Define.EVENTFUL_SEARCH_REQUEST;
			url = url.replace("@app_key", Define.EVENTFUL_API_KEY);
			url = url.replace("@location", latitude + "," + longitude);
			url = url.replace("@within", String.valueOf(radiusMetters));
			url = url.replace("@page_size", String.valueOf(Globals.MAX_NUMBER_OF_SEARCHED_LOCATIONS));
			
			SAXParserFactory spf = SAXParserFactory.newInstance();
			spf.setValidating(false);
			InputStream inputStream = HttpProvider.getInputStream(url);
			EventfulHandler eventfulHandler = new EventfulHandler();
			Xml.parse(inputStream, Xml.Encoding.UTF_8, eventfulHandler);
			return eventfulHandler.getListResults();
		} catch (Exception e) {
			// TODO: handle exception
			String msg = e.getMessage();
			if (msg != null) {
				Log.d(TAG, msg);
			}
			return null;
		}
	}

	@Override
	public ArrayList<Place> getListPlacesByType(String latitude,
			String longitude, String type, int radiusMetters) {
		// TODO Auto-generated method stub
		return null;
	}
}
